from enum import Enum
from typing import List


class FieldType(Enum):
    """字段类型枚举"""
    TEXT = "text"
    TEXTAREA = "textarea"

    @classmethod
    def get_all_types(cls) -> List[str]:
        """获取所有字段类型的值列表"""
        return [member.value for member in cls]

    @classmethod
    def is_valid_type(cls, field_type: str) -> bool:
        """验证字段类型是否有效"""
        return field_type in cls.get_all_types()

    @classmethod
    def from_string(cls, field_type: str) -> 'FieldType':
        """从字符串获取枚举实例"""
        for member in cls:
            if member.value == field_type:
                return member
        raise ValueError(f"Invalid field type: {field_type}")

# # 使用示例
# print(FieldType.TEXT)        # FieldType.TEXT
# print(FieldType.TEXT.value)  # "text"
# print(FieldType.TEXTAREA.value)  # "textarea"
# # 使用示例
# print(FieldType.get_all_types())  # ['text', 'textarea']
# print(FieldType.is_valid_type("text"))  # True
# print(FieldType.is_valid_type("invalid"))  # False